﻿using Halcon二次开发.Model;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.输入框
{
    public partial class NameCopyForm : Form
    {
        public string name="";
        public NameCopyForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || StaicResouce.FilesName.Keys.Contains(textBox1.Text)||textBox1.Text.Contains("工程文件"))
            {
                MessageBox.Show("文件名称为空,重复文件名称或出现敏感词!");
                this.Close();
                return;
            }
            this.name = textBox1.Text.Trim();
            string path = $@"Data\工程文件\{textBox1.Text.Trim()}";
            try
            {
                // 检查文件夹是否已存在  
                if (!Directory.Exists(path))
                {
                    // 如果文件夹不存在，则创建它  
                    Directory.CreateDirectory(path);

                    //File.Create(path + "\\系统文件.xml").Close();
                    //File.WriteAllText(path + "\\系统文件.xml", "最终版权为: 蒋佳航,蒋佳峻,屈忠辉");

                    //FileAttributes attributes = File.GetAttributes(path + "\\系统文件.xml");
                    //attributes |= FileAttributes.Hidden;
                    //File.SetAttributes(path + "\\系统文件.xml", attributes);

                    (FormDb.Db["Form1"] as Form1).textBox1.AppendText("工程文件夹已另存为：" + path + "\r\n");
                }
                else
                {
                    name = "";
                    MessageBox.Show("该工程已经存在了!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                name = "";
                // 捕获并处理可能发生的异常  
                MessageBox.Show("创建工程文件夹时发生错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Close();
        }
        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
